﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TTDataAccess;
using TTEntity;
using System.Data;

namespace TTBusiness
{
    public class clsBSProduct
    {
        clsDAProduct objDA = new clsDAProduct();
        private clsProduct getDataFromRow(DataRow dr)
        {
            try
            {
                clsProduct obj = new clsProduct();
                if (!dr.Equals(null))
                {
                    if (!dr.IsNull("ID"))
                        obj.Id = Convert.ToInt32(dr["ID"]);
                    if (!dr.IsNull("Name"))
                        obj.Name = dr["Name"].ToString();
                    if (!dr.IsNull("Number"))
                        obj.Number = Convert.ToInt32(dr["Number"]);
                    if (!dr.IsNull("Product"))
                        obj.Price = (float)Convert.ToDouble(dr["Product"]);
                    if (!dr.IsNull("Detail"))
                        obj.Detail = dr["Detail"].ToString();
                    if (!dr.IsNull("Image"))
                        obj.Image = dr["Image"].ToString();
                    if (!dr.IsNull("Visible"))
                        obj.Visible = Convert.ToBoolean(dr["Visible"]);
                    if (!dr.IsNull("Status"))
                        obj.Status = Convert.ToBoolean(dr["Status"]);
                    if (!dr.IsNull("FactoryID"))
                        obj.FactoryId = Convert.ToInt32(dr["FactoryID"]);
                    if (!dr.IsNull("Summary"))
                        obj.Summary = dr["Summary"].ToString();
                    if (!dr.IsNull("SeriNumber"))
                        obj.SeriNumber = dr["SeriNumber"].ToString();
                    if (!dr.IsNull("View"))
                        obj.View = Convert.ToInt32(dr["View"]);
                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public List<clsProduct> getAll()
        {
            try
            {

                List<clsProduct> objList = new List<clsProduct>();
                DataTable dt = new DataTable();
                dt = objDA.GetAll();
                foreach (DataRow dr in dt.Rows)
                {
                    clsProduct account = new clsProduct();
                    account = getDataFromRow(dr);
                    objList.Add(account);
                }
                return objList;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void Insert(clsProduct obj)
        {
            try
            {
                objDA.Insert(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void Update(clsProduct obj)
        {
            try
            {
                objDA.Update(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void Delete(int id)
        {
            try
            {
                objDA.Delete(id);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
